# -*- coding: utf-8 -*-

"""
@Author: 芮芪懿 QQ1849433491
@Project->File: pygame_train -> file_op.py
@IDE：PyCharm
@File: file_op.py
@Datetime: 2021/7/10 23:48
"""


def read_file():
    with open("./resources/rank_list.txt", "r+", encoding="utf-8") as fp:
        content = fp.readline()
        rank_list = content.split("#")
        rank_list_int = []
        for rank in rank_list:
            rank_list_int.append(int(rank))
        rank_list_int.sort()
        rank_list_int.reverse()
        return rank_list_int


def write_file(rank_list=[]):
    with open("./resources/rank_list.txt", "w+", encoding="utf-8") as fp:
        # rank_list = [8004, 7877, 7457, 474, 454]
        # rank_list = [8004, 7877, 7457, 474, 454]
        # rank_list.append(787)
        rank_list.sort()
        rank_list.reverse()
        # print(rank_list)
        rank_list_str = ""
        for i in range(len(rank_list)-1):
            rank_list_str += f"{rank_list[i]}#"
        rank_list_str = rank_list_str[0:len(rank_list_str)-1]
        print(rank_list_str)
        fp.write(rank_list_str)
        # print(rank_list)
        pass
    pass


if __name__ == '__main__':
    write_file(read_file())
    # read_file()
